package com.zrm.zfcrpa.configuration.security.mobile;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

public class SmsCodeAuthToken extends AbstractAuthenticationToken {

    private static final long SerialVersionUID = 500L;

    //存放手机号码
    private final  Object principal;

    public SmsCodeAuthToken(Object mobile) {
        super((Collection)null);
        this.principal = mobile;
        this.setAuthenticated(false);
    }

    public SmsCodeAuthToken(Object principal,Collection<? extends GrantedAuthority> authorities){
        super(authorities);
        this.principal = principal;
        super.setAuthenticated(true);
    }

    public void setAuthenticated(boolean isAuthenticated) {
        if(isAuthenticated){
            try {
                throw new IllegalAccessException("cant set this token to trusted - user construtr");
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }else {
            super.setAuthenticated(false);
        }

    }

    public void eraseCredentials(){
        super.eraseCredentials();
    }

    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }
}
